package com.hjb.service.impl.user;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hjb.service.config.constant.Constants;
import com.hjb.service.domain.siteuser.SiteUserAccountLog;
import com.hjb.service.mapper.SiteSysAccountMapper;
import com.hjb.service.mapper.SiteUserAccountLogMapper;
import com.hjb.service.user.SiteSysAccountService;

/**
 * 系统账户接口业务实现类
 * @author zhangxl
 * @date 2017-08-16
 * @version 1.0
 */
@Service
public class SiteSysAccountServiceImpl implements SiteSysAccountService{

	@Autowired
	private SiteSysAccountMapper siteSysAccountMapper;
	@Autowired
	private SiteUserAccountLogMapper siteUserAccountLogMapper;
	
	@Override
	public int updateBanlanceByUserId(Integer userId, BigDecimal currentAmount,BigDecimal frozenAccount,int acctType,
			Integer inAccount, Integer outAccount, String orderId,String currnetOrder, String fixedOrder, String desc,
			String inMsg,String outMsg) {
		Map<String,Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		params.put("currentAmount", currentAmount);
		params.put("frozenAmount", frozenAccount);
		int res = siteSysAccountMapper.updateBanlanceByUserId(params);
		int status = Constants.COMMON_STATUS_1;
		if(res !=1){
			status = Constants.COMMON_STATUS_2;
		}
		
		//记录日志
		SiteUserAccountLog userAccountLog = new SiteUserAccountLog();
		userAccountLog.setUserId(userId);
		userAccountLog.setAcctType(acctType);
		userAccountLog.setCreateTime(new Date());
		userAccountLog.setInAccount(inAccount);
		userAccountLog.setOutAccount(outAccount);
		userAccountLog.setAmount(currentAmount);
		userAccountLog.setStatus(status);
		userAccountLog.setOrderId(orderId);
		userAccountLog.setCurrnetOrder(currnetOrder);
		userAccountLog.setFixedOrder(fixedOrder);
		userAccountLog.setInfo(desc);
		userAccountLog.setInMsg(inMsg);
		userAccountLog.setOutMsg(outMsg);
		
		siteUserAccountLogMapper.insertSelective(userAccountLog);
		return res;
	}

}
